import { CTableProps } from '@/components/CTable';
import type { TableFieldsSettingType } from '@/components/CPageTable';
import { getListPlant } from '@/apis/system/config/factoryWorkshopMeterSet';

export const useTableList = () => {
  // 表格配置
  const tableOptions: CTableProps = {
    loadData,
    pagination: false
  };

  function loadData() {
    return getListPlant().then(res => {
      return {
        records: res,
        total: res?.length || 0
      };
    });
  }

  const tableFieldsSetting: TableFieldsSettingType[] = [
    {
      title: '工厂ID',
      field: 'plantId',
      minWidth: 130
    },
    {
      title: '工厂名称/工厂编号',
      field: 'plantName',
      slot: 'plantNameSlot',
      minWidth: 130
    },
    {
      title: '组织名称/组织编号',
      field: 'organizationName',
      slot: 'organizationNameSlot',
      minWidth: 130
    },
    {
      title: '操作',
      field: 'op',
      slot: 'op',
      width: 160,
      fixed: 'right'
    }
  ];

  return {
    tableOptions,
    tableFieldsSetting
  };
};
